/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUI.java
 *
 * Created on 12.11.2009, 12:52:58
 */

package iddsgui;

import Main.Parameters;
import javax.swing.UIManager;
import system.UserInputStream;

/**
 *
 * @author zem
 */
public class GUI extends javax.swing.JFrame {

    /** Creates new form GUI */
    public GUI() {

        initComponents();
        Parameters.GUIAvailable = true;
    }
    

    public static GUI instance;

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        TabsPanel = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TaskListTable = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        ConsoleInputField = new javax.swing.JTextField();
        ButtonInput = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        ConsoleTextArea = new javax.swing.JTextArea();
        jMenuBar1 = new javax.swing.JMenuBar();
        MenuFile = new javax.swing.JMenu();
        MenuFile_Close = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        MenuFile_Exit = new javax.swing.JMenuItem();
        MenuEdit = new javax.swing.JMenu();
        MenuEdit_CreateTask = new javax.swing.JMenuItem();
        MenuEdit_Parameters = new javax.swing.JMenuItem();
        MenuInfo = new javax.swing.JMenu();
        MenuInfo_About = new javax.swing.JMenuItem();
        MenuInfo_Help = new javax.swing.JMenuItem();

        setMinimumSize(new java.awt.Dimension(800, 600));

        TabsPanel.setRequestFocusEnabled(false);

        TaskListTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "java.lang.Object@6b19ae3e", "java.lang.Object@6b19ae3e", "java.lang.Object@6b19ae3e", "java.lang.Object@6b19ae3e"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(TaskListTable);
        TaskListTable.getColumnModel().getColumn(0).setMinWidth(40);
        TaskListTable.getColumnModel().getColumn(0).setPreferredWidth(40);
        TaskListTable.getColumnModel().getColumn(0).setMaxWidth(200);
        TaskListTable.getColumnModel().getColumn(0).setHeaderValue(Parameters.GUI_TaskList_number);
        TaskListTable.getColumnModel().getColumn(1).setHeaderValue(Parameters.GUI_TaskList_name);
        TaskListTable.getColumnModel().getColumn(2).setHeaderValue(Parameters.GUI_TaskList_starttime);
        TaskListTable.getColumnModel().getColumn(3).setMinWidth(120);
        TaskListTable.getColumnModel().getColumn(3).setPreferredWidth(120);
        TaskListTable.getColumnModel().getColumn(3).setMaxWidth(400);
        TaskListTable.getColumnModel().getColumn(3).setHeaderValue(Parameters.GUI_TaskList_done);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 796, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
        );

        TabsPanel.addTab("Tasks", jPanel1);

        ButtonInput.setText("INPUT");
        ButtonInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonInputActionPerformed(evt);
            }
        });

        ConsoleTextArea.setColumns(20);
        ConsoleTextArea.setRows(5);
        jScrollPane2.setViewportView(ConsoleTextArea);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 772, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(ConsoleInputField, javax.swing.GroupLayout.DEFAULT_SIZE, 716, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButtonInput)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ConsoleInputField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ButtonInput))
                .addContainerGap())
        );

        TabsPanel.addTab("Console", jPanel2);

        MenuFile.setText("File");

        MenuFile_Close.setText("Close");
        MenuFile_Close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuFile_CloseActionPerformed(evt);
            }
        });
        MenuFile.add(MenuFile_Close);
        MenuFile.add(jSeparator1);

        MenuFile_Exit.setText("Exit");
        MenuFile_Exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuFile_ExitActionPerformed(evt);
            }
        });
        MenuFile.add(MenuFile_Exit);

        jMenuBar1.add(MenuFile);

        MenuEdit.setText("Edit");

        MenuEdit_CreateTask.setText("Create Task");
        MenuEdit_CreateTask.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuEdit_CreateTaskActionPerformed(evt);
            }
        });
        MenuEdit.add(MenuEdit_CreateTask);

        MenuEdit_Parameters.setText("Parameters");
        MenuEdit_Parameters.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuEdit_ParametersActionPerformed(evt);
            }
        });
        MenuEdit.add(MenuEdit_Parameters);

        jMenuBar1.add(MenuEdit);

        MenuInfo.setText("Info");

        MenuInfo_About.setText("About");
        MenuInfo_About.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuInfo_AboutActionPerformed(evt);
            }
        });
        MenuInfo.add(MenuInfo_About);

        MenuInfo_Help.setText("Help");
        MenuInfo_Help.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuInfo_HelpActionPerformed(evt);
            }
        });
        MenuInfo.add(MenuInfo_Help);

        jMenuBar1.add(MenuInfo);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(TabsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(TabsPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 575, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Input line to currently active library
     * @param evt - Action Event
     */
    private void ButtonInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonInputActionPerformed
        new UserInputStream().Input(ConsoleInputField.getText());
        ConsoleInputField.setText("");
    }//GEN-LAST:event_ButtonInputActionPerformed

    private void MenuEdit_ParametersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuEdit_ParametersActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_MenuEdit_ParametersActionPerformed

    /**
     * Show CreateTaskFrame (menu Edit->Task Create)
     * @param evt - action event
     */
    private void MenuEdit_CreateTaskActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuEdit_CreateTaskActionPerformed
        new CreateTaskFrame().main();
    }//GEN-LAST:event_MenuEdit_CreateTaskActionPerformed

    /**
     * Close this window(menu File->Close)
     * @param evt - action event
     */
    private void MenuFile_CloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuFile_CloseActionPerformed
        dispose();
    }//GEN-LAST:event_MenuFile_CloseActionPerformed

    /**
     * Show ExitAskFrame (File->Exit)
     * @param evt - action event
     */
    private void MenuFile_ExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuFile_ExitActionPerformed
        new ExitAskFrame().main();
    }//GEN-LAST:event_MenuFile_ExitActionPerformed

    /**
     * Show AboutFrame (Info->About)
     * @param evt - action event
     */
    private void MenuInfo_AboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuInfo_AboutActionPerformed
        new AboutFrame().main();
    }//GEN-LAST:event_MenuInfo_AboutActionPerformed

    /**
     * Show HelpFrame (Info->Help)
     * @param evt
     */
    private void MenuInfo_HelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuInfo_HelpActionPerformed
        new HelpFrame().main();
    }//GEN-LAST:event_MenuInfo_HelpActionPerformed

    

    /**
    * @param args the command line arguments
    */
    public void main() {

         // Set System L&F
        try{
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ex) {
        }


        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                //new instance of GUI
                instance=new GUI();
                
                instance.setTitle(Parameters.GUI_MainTitle);
                instance.ButtonInput.setDefaultCapable(true);
                instance.rootPane.setDefaultButton(ButtonInput);

                //set menu names
                instance.MenuFile.setText(Parameters.GUI_MenuFile);
                instance.MenuEdit.setText(Parameters.GUI_MenuEdit);
                instance.MenuInfo.setText(Parameters.GUI_MenuInfo);
                //set menu component names
                instance.MenuFile_Close.setText(Parameters.GUI_MenuFile_Close);
                instance.MenuFile_Exit.setText(Parameters.GUI_MenuFile_Exit);
                instance.MenuEdit_CreateTask.setText(Parameters.GUI_MenuEdit_TaskCreate);
                instance.MenuEdit_Parameters.setText(Parameters.GUI_MenuEdit_Parameters);
                instance.MenuInfo_About.setText(Parameters.GUI_MenuInfo_About);
                instance.MenuInfo_Help.setText(Parameters.GUI_MenuInfo_Help);
                //set Tab names
                instance.TabsPanel.setTitleAt(0, Parameters.GUI_TaskTabTitle);
                instance.TabsPanel.setTitleAt(1, Parameters.GUI_ConsoleTabTitle);
                //set Button names
                instance.ButtonInput.setText(Parameters.GUI_ButtonInput);

                
                //set GUI visible
                instance.setVisible(true);

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonInput;
    private javax.swing.JTextField ConsoleInputField;
    public javax.swing.JTextArea ConsoleTextArea;
    private javax.swing.JMenu MenuEdit;
    private javax.swing.JMenuItem MenuEdit_CreateTask;
    private javax.swing.JMenuItem MenuEdit_Parameters;
    private javax.swing.JMenu MenuFile;
    private javax.swing.JMenuItem MenuFile_Close;
    private javax.swing.JMenuItem MenuFile_Exit;
    private javax.swing.JMenu MenuInfo;
    private javax.swing.JMenuItem MenuInfo_About;
    private javax.swing.JMenuItem MenuInfo_Help;
    private javax.swing.JTabbedPane TabsPanel;
    private javax.swing.JTable TaskListTable;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables

}
